const express = require('express');
const ejs = require('ejs');
const path = require('path');

const app = express();

app.get(/.*\.sh$/,(req,res) => {
  const host = req.headers.host;
  if(!host){
    res.send('host 错误');
    res.status(500);
    return;
  }
  ejs.renderFile(path.join(__dirname,req.originalUrl),{
    '$host':host
  },(err,str)=>{
    if(err){
      res.status(404).send(err.message);
    }else {
      res.setHeader('Content-Type','application/x-sh');
      res.send(str);
    }
  });
})

app.use(express.static(__dirname));

app.listen(4000);
